package com.zrgj.manager.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.zrgj.common.response.BaseResponse;
import com.zrgj.common.response.StatusCodeEnum;
import com.zrgj.domain.Primary;
import com.zrgj.manager.service.IPrimaryService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class PrimaryController {
    @Reference
    private IPrimaryService primaryService;

    /**
     * 获取分类列表
     * @return
     */
    @RequestMapping("/getPrimary")
    public BaseResponse getPrimary(){
        List<Primary> primaries = primaryService.selectPrimaryList();
        return new BaseResponse<>(StatusCodeEnum.SUCCESS,primaries);
    }

    /**
     * 回显
     * @param primaryId
     * @return
     */
    @RequestMapping(value = "/showPrimary")
    public BaseResponse showPrimary(Integer primaryId){
        Primary primary = primaryService.selectPrimary(primaryId);
        return new BaseResponse(StatusCodeEnum.SUCCESS,primary);
    }

    /**
     * 修改分类
     * @param primary
     * @return
     */
    @RequestMapping(value = "/editPrimary")
    public BaseResponse editPrimary(@RequestBody Primary primary){
        primaryService.update(primary);
        return new BaseResponse(StatusCodeEnum.SUCCESS);
    }

    /**
     * 添加分类
     * @param primary
     * @return
     */
    @RequestMapping(value = "/addPrimary")
    public BaseResponse addPrimary(@RequestBody Primary primary){
        primaryService.insert(primary);
        return new BaseResponse(StatusCodeEnum.SUCCESS);
    }

    /**
     * 删除分类
     * @param primaryId
     * @return
     */
    @RequestMapping(value = "/delPrimary")
    public BaseResponse delPrimary(Integer primaryId){
        primaryService.delete(primaryId);
        return new BaseResponse(StatusCodeEnum.SUCCESS);
    }

}
